package com.avetti.commerce.webservices;

import java.util.List;

import org.codehaus.xfire.fault.XFireFault;

import com.avetti.commerce.inventory.domainmodel.InventoryHistory;

/**
 * A web service of inventories. Required to authenticate a user and set
 * vendor id to work with, before launch any service method
 * @author A.Nadtochey
 *
 * @see WebServiceAuthHandler
 * @see WebServiceVendorIdHandler
 *
 */
public interface InventoryService {
    /**
     * Find all inventories which, specified vendor has
     * @return list of vendor's inventories, if no inventories has found,
     * @param context SOAP message context 
     * an empty list will return
     */
    public List<Inventory> find();
    /**
     * Find inventory for the specified vendor and item
     * @param itemId item identifier
     * @param context SOAP message context 
     * @return list of vendor's inventories, if no inventories has found, 
     * an empty list will return
     */
    public List<Inventory> findByItemId(Long itemId );
    /**
     * Find inventory object
     * @param inventoryId inventory identifier
     * @param context SOAP message context 
     * @return inventory object or null if it does not exists
     */
    public Inventory find(Long inventoryId );
    /**
     * Find item's inventories.
     * @param itemIdList list of item id, for inventory to find
     * @param context SOAP message context 
     * @return list of found inventories, or empty list if no inventories
     * has been found
     */
    public List<Inventory> findByItemId(List<Long> itemIdList 
            );
    /**
     * Find inventories that contains value of inStock less than specified
     * @param lessInStock value
     * @param context SOAP message context 
     * @return list of found inventories, or empty list if no inventories
     * has been found
     */
    public List<Inventory> findByInStock(Long lessInStock 
            );
    /**
     * Find inventories that contains value of inOrder more than specified
     * @param moreOrder value
     * @param context SOAP message context 
     * @return list of found inventories, or empty list if no inventories
     * has been found
     */
    public List<Inventory> findByMoreOrder(Long inOrder );
    /**
     * Create inventory into the database
     * @param inventory object to create
     * @param context SOAP message context 
     * @throws NoVendorException if vendor has not specified (null or empty) 
     * into the inventory object
     */
    public void create(Inventory inventory ) 
    throws XFireFault;
    /**
     * Update an inventory
     * @param context SOAP message context 
     * @param inventory object to update
     * @throws XFireFault 
     */
    public void update(Inventory inventory ) throws XFireFault;
    /**
     * Delete inventory
     * @param context SOAP message context 
     * @param inventory object to delete
     */
    public void delete(Inventory inventory );
    /**
     * Delete list of inventories
     * @param context SOAP message context 
     * @param inventoryList list of objects to delete
     */
    public void delete(List<Inventory> inventoryList );
    /**
     * Delete all vendor's inventories
     * @param context SOAP message context 
     */
    public void delete();
    /**
     * Find inventories for item by sucode
     * @param item item
     * @param subcode subcode
     * @param context SOAP message context 
     * @return inventory list
     */
    List<Inventory> findBySubcode(Items item, String subcode 
            );
    /**
     * Find all inventories for vendor by item composite code 
     * @param itemCompCode item composite code
     * @param context SOAP message context 
     * @return List of inventories
     */
    public List<Inventory> findByItemCode(String itemCompCode 
            );  
    /**
     * Find item's inventories.
     * @param vendorId vendor identifier
     * @param itemCompCodeList list of item code, for inventory to find
     * @return list of found inventories, or empty list if no inventories
     * has been found
     */
    public List<Inventory> findByItemCode(List<String> itemCompCodeList
            ); 
    /**
     * go through the invhist table to find which record's timestamp+expiredTime is greater than now 
     * where invhist.orderdataid is null and status={@link InventoryHistory#Status#ACTIVE};
     * @param expiredtime expired time in ms
     * @return list of found inventoryhistory or empty list if no record
     */
    public List<InventoryHistory> findExpired(long expiredtime 
            );
     
    /**
     * Load inventoryhistory by primary identifier
     * @param invhistid invhist identifier
     * @param context SOAP message context 
     * @return inventoryhistory object or null if it does not exists
     */
    public InventoryHistory findInventoryHistory(Long invhistid 
            );
     
    /**
     * update inventory and insert/update invhist, the two steps need in a transaction 
     * @param allinventory inventory need to update,include base code record if have
     * @param allInventoryHistory if invhistid==null insert otherwise update, 
     * @param context SOAP message context 
     * @return always return the first element's invhistid
     */
    public Long balanceInventory(List<Inventory> allinventory, 
            List<InventoryHistory> allInventoryHistory );
}
